package cn.hz.pi.api.inteface;

import com.sun.jna.Library;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.FloatByReference;
import com.sun.jna.ptr.IntByReference;

/**
 * PI·API接口方法一览
 * 
 * @author huazhuo
 *
 */
public interface PiApiMethod extends Library {

	/**
	 * 获取测点快照信息
	 * 
	 * @param id
	 *            (passed)测点ID
	 * @param rval
	 *            (returned)测点值
	 * @param istat
	 *            (returned)测点状态
	 * @param timedate
	 *            (returned)时间戳
	 * @return
	 */
	public int pisn_getsnapshot(int id, FloatByReference rval, IntByReference istat, IntByReference timedate);

	public int pipt_tag(int id, Pointer name, int type);

	/**
	 * 根据指定时点,获取测点值
	 * 
	 * @param id
	 *            (passed)测点ID
	 * @param timedate
	 *            (passed, returned)时间戳
	 * @param model
	 * @param revl
	 *            (returned)测点值
	 * @param state
	 *            (returned)状态
	 * @return
	 */
	public int piar_value(int id, IntByReference timedate, int model, FloatByReference revl, IntByReference state);

	/**
	 * 计算测点值
	 * 
	 * @param id
	 *            (passed)测点ID
	 * @param startTime
	 *            (passed, returned)开始时点
	 * @param endTime
	 *            (passed, returned)结束时点
	 * @param rval
	 *            (returned)计算值
	 * @param pctgood
	 *            (returned)Percent of time Archive value was good
	 * @param code
	 *            (passed)计算类型
	 * @return
	 */
	public int piar_summary(int id, IntByReference startTime, IntByReference endTime, FloatByReference rval,
			FloatByReference pctgood, int code);

	/**
	 * 获取测点存档值
	 * 
	 * @param id
	 *            测点ID (passed)
	 * @param count
	 *            返回值个数(passed, returned)
	 * @param times
	 *            时间数组(passed, returned)
	 * @param rvals
	 *            值(returned)
	 * @param states
	 *            状态(returned)
	 * @param rev
	 *            (passed) Reverse sequence flag. If false (zero), search will
	 *            be forwards in time; if true (non zero), search will be
	 *            backwards.
	 * @return
	 */
	public int piar_compvalues(int id, IntByReference count, int[] times, float[] rvals, int[] states, int rev);

	/**
	 * 
	 * @param id
	 *            测点ID
	 * @param count
	 *            返回值个数(passed, returned)
	 * @param times
	 *            时间数组(passed, returned)
	 * @param rvals
	 *            值(returned)
	 * @param states
	 *            状态(returned)
	 * @return
	 */
	public int piar_interpvalues(int id, IntByReference count, int[] times, float[] rvals, int[] states);

	public int piar_putvalue(int id, float rval, int istate, int timedate, int wite);

	public int piar_deletevalue(int pointId, int time);

	// 时间方法
	public int pitm_intsec(IntByReference time, int[] timearray);

	public void pitm_formtime(int timedate, Pointer timestr, int length);

	/**
	 * 
	 * @param count
	 * @param times
	 * @param rvals
	 * @param istats
	 * @param calcstr
	 *            公式
	 * @return
	 */
	public int piar_calculation(IntByReference count, int[] times, float[] rvals, int[] istats, String calcstr);

	/**
	 * 获取测点ID
	 * 
	 * @param name
	 *            (passed)测点名称
	 * @param ptId
	 *            (returned)测点ID
	 * @return
	 */
	public int pipt_findpoint(String name, IntByReference ptId);

	public int pipt_ptexist(int pointId);

	public int pipt_pointtype(int pointId, Pointer pointType, int len);

	public int pipt_engunitstring(int pointId, Pointer unit, int len);

	public int pipt_inprocbits(int pointId, IntByReference larchiving, IntByReference lcompressing,
			IntByReference filtercode);

	public int pipt_compspecs(int pointId, IntByReference compdev, IntByReference compmin, IntByReference compmax);

	public int pipt_descriptor(int pointId, Pointer desc, int len);

	public int pipt_displaydigits(int pointId, IntByReference displaydigits);

	public int pipt_exdesc(int pointId, Pointer exdesc, int len);

	public int pipt_pointsource(int pointId, Pointer exdesc);

	public int pipt_location(int pointId, int[] location);

	public int pisn_getsnapshots(int[] pt, float[] rval, IntByReference[] istat, IntByReference[] timedate,
			IntByReference[] error, int rcount);

	public int pisn_getsnapshot(IntByReference ptId, FloatByReference value, IntByReference istat,
			IntByReference timedate);

	public int pisn_getsnapshots(int[] pt, float[] rval, int[] istat, int[] timedate, int[] error, int rcount);

	public int pipt_findpoint(String name, Pointer pointer);

	/**
	 * 保存测点快照值
	 * 
	 * @param pt
	 *            (passed)测点ID
	 * @param rval
	 *            (passed)测点值
	 * @param istat
	 *            (passed)状态
	 * @param timedate
	 *            (passed)时间戳
	 * @return
	 */
	public int pisn_putsnapshot(int pt, float rval, int istat, int timedate);

	/**
	 * 批量保存测点快照值
	 * 
	 * @param pt
	 *            (passed)测点ID
	 * @param rval
	 *            (passed)测点值
	 * @param istat
	 *            (passed)状态
	 * @param timedate
	 *            (passed)时间戳
	 * @param error
	 *            (returned)
	 * @param count
	 *            (passed)个数
	 * @return
	 */
	public int pisn_putsnapshots(int[] pt, float[] rval, int[] istat, int[] timedate, IntByReference[] error,
			int count);

	public int pitm_parsetime(String str, int reltime, IntByReference timedate);

	public int pitm_secint(int time, int[] timearray);

	/**
	 * 判断PI数据库的连接状态
	 * 
	 * @return
	 */
	public int piut_isconnected();

	/**
	 * 若未建立信任连接，需使用用户名及密码登录PI数据库
	 * 
	 * @param username
	 *            (passed)用户名
	 * @param password
	 *            (passed)密码
	 * @param valid
	 *            (returned)Level of access available
	 * 
	 * @return
	 */
	public int piut_login(String username, String password, IntByReference valid);

	/**
	 * 链接PI数据库
	 * 
	 * @param ip
	 *            PI服务器地址
	 * @return
	 */
	public int piut_setservernode(String ip);
	
	public int pipt_digstate(int digcode, Pointer unit, int a);

}
